package com.health.mapp.service;

import java.io.IOException;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.chainsaw.Main;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.health.db.model.UserRecommRemark;
import com.health.db.service.user.IUserRecommRemarkService;

/**
 * Servlet implementation class RongCloudCallBack
 */
public class UserRecommServer extends HttpServlet {
    /**
     * @see HttpServlet#HttpServlet()
     */

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		ServletContext servletContext = request.getSession().getServletContext();
		ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);  

		IUserRecommRemarkService userRecommRemarkService = (IUserRecommRemarkService) applicationContext.getBean("userRecommRemarkService");
		//IIMsgIMMessageService   iMsgIMMessageService=(IIMsgIMMessageService) applicationContext.getBean("iMsgIMMessageService");
		String businessCode = request.getParameter("bcode");
		
		if (StringUtils.isNotBlank(businessCode)) {
			businessCode =businessCode.replace(",", "");
			String phone = request.getParameter("phone");
			UserRecommRemark remark = new UserRecommRemark();
			remark.setUserPhone(phone);
		
			//拆分渠道
			if (businessCode.startsWith("C")) {
				remark.setUsedflag((short) 9);
				businessCode=businessCode.replace("C", "");
			}else{
				remark.setUsedflag((short) 0);
			}
			remark.setBusinessCode(businessCode);
			userRecommRemarkService.insert(remark);
		}
		
	}
	
	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		super.destroy();
	}
	
	@Override
	public void init() throws ServletException {
		// TODO Auto-generated method stub
		super.init();
	}
}
